package com.tk.exam.web.admin;

import com.alibaba.fastjson.JSONObject;
import com.tk.exam.domain.TkQuestionCategory;
import com.tk.exam.domain.TkQuestions;
import com.tk.exam.http.Response;
import com.tk.exam.service.TkQuesCategoryService;
import com.tk.exam.service.TkQuestionService;
import com.tk.exam.utils.JsonUtils;
import com.tk.exam.utils.PageInfo;
import com.tk.exam.vo.question.TkQuestionVo;
import com.tk.exam.vo.question.req.*;
import com.tk.exam.vo.question.resp.TkAnswerVo;
import com.tk.exam.vo.question.resp.TkQuestionTotalVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;


@RestController
@RequestMapping("tk/exam/admin/quesCategory")
@Slf4j
public class TkQuesCategoryController {

    @Autowired
    TkQuesCategoryService tkQuesCategoryService;

    /**
     * 分页查询以WithPage结尾
     *
     * @param :
     * @return
     */
    @RequestMapping(value = "/searchQuesCategoryList", method = RequestMethod.POST)
    public Response searchQuesCategoryListWithPage() {
        //查询分页数据
        com.github.pagehelper.PageInfo<TkQuestionCategory> pageInfoHelper = tkQuesCategoryService.searchList();
        PageInfo pageInfo = new PageInfo(pageInfoHelper);
        return Response.succeed(pageInfo);
    }


    @RequestMapping(value = "/searchQuesCategorys", method = RequestMethod.GET)
    public Response searchQuesCategoryList() {
        List<TkQuestionCategory> tkQuestionCategories = tkQuesCategoryService.searchListNoPage();
        return Response.succeed().put("questionCategories",tkQuestionCategories);
    }

    /**
     * 新增试题缺陷类型
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/addTkQuesCategory", method = RequestMethod.POST)
    public Response addTkQuesCategory(@RequestBody TkQuestionCategory tkQuestionCategory) {
        if(StringUtils.isBlank(tkQuestionCategory.getCategoryName())){
            return Response.fail("分类名称不能为空");
        }
        tkQuesCategoryService.save(tkQuestionCategory);
        return Response.succeed();
    }
    @RequestMapping(value = "/editTkQuesCategory",method = RequestMethod.POST)
    public Response editTkQuesCategory(@RequestBody TkQuestionCategory tkQuestionCategory){
        Integer id = tkQuestionCategory.getId();
        if(Objects.isNull(id)){
            return Response.fail("id不能为空");
        }
        if(StringUtils.isBlank(tkQuestionCategory.getCategoryName())){
            return Response.fail("分类名称不能为空");
        }
        tkQuesCategoryService.save(tkQuestionCategory);
        return Response.succeed();
    }

}
